import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart';

class AnimationPage extends StatefulWidget {
  AnimationPage({Key? key}) : super(key: key);

  @override
  State<AnimationPage> createState() => _AnimationPageState();
}

class _AnimationPageState extends State<AnimationPage> {
  Timer timer = Timer(const Duration(seconds: 5), () => print('Timer finished'));
  bool click = false;

  @override
  Widget build(BuildContext context) {
    var read = context.read<AnimationModel>();
    var watch = context.watch<AnimationModel>();
    return Scaffold(
      body: Container(
        alignment: Alignment.center,
        color: HexColor("#EEEEEE"),
        child: IgnorePointer(
          ignoring: click,
          child: InkWell(
            onTap: () {
              read.up();
              click = true;
              timer = Timer.periodic(Duration(seconds: 5), (t) {
                read.up();
                Fluttertoast.showToast(
                  msg: "😂🤣🤣🤣😂😁😁💖💖😢💖😢💖😢💖💖💖",
                  toastLength: Toast.LENGTH_LONG,
                  gravity: ToastGravity.TOP,
                  timeInSecForIosWeb: 1,
                  backgroundColor: Colors.white10,
                  textColor: Color.fromARGB(255, 61, 59, 59),
                  fontSize: 16.0,
                );
              });
            },
            child: AnimatedContainer(
              duration: Duration(seconds: 2),
              decoration: BoxDecoration(
                color: Colors.amberAccent,
                borderRadius: BorderRadius.all(Radius.circular(watch.circular)),
              ),
              width: watch.width,
              height: watch.height,
            ),
          ),
        ),
      ),
      floatingActionButton: click
          ? FloatingActionButton(
              backgroundColor: Colors.red,
              child: Text("stop", style: TextStyle(fontSize: 15.sp)),
              onPressed: () {
                setState(() {
                  click = false;
                  timer.cancel();
                });
              },
            )
          : null,
    );
  }
}

class AnimationModel with ChangeNotifier {
  double width = 300;
  double height = 300;
  double circular = 0;

  //增大
  void up() {
    if (height == 600) {
      height = width = 300;
      circular = 200;
    } else {
      height = width = 600;
      circular = 0;
    }
    notifyListeners();
  }
}
